﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PBO.Data
{

    public class BattleStats : ICloneable, IEnumerable<int>
    {
        public readonly static StatType[] Type7D = { StatType.Atk, StatType.Def, StatType.Speed, StatType.SpAtk, StatType.SpDef, StatType.Accuracy, StatType.Evasion };
        public readonly static StatType[] Type5D = { StatType.Atk, StatType.Def, StatType.Speed, StatType.SpAtk, StatType.SpDef };

        #region Fun

        private int[] stats = new int[7];

        public BattleStats() : this(0) { }

        public BattleStats(int value)
        {
            stats = Enumerable.Repeat<int>(value, 7).ToArray();
        }

        public BattleStats(BattleStats stats)
        {
            SetValue(stats);
        }

        public void SetAll(int value)
        {
            foreach (StatType stat in Type7D)
            {
                this[stat] = value;
            }
        }

        public void SetValue(BattleStats stats)
        {
            foreach (StatType stat in Type7D)
            {
                this[stat] = stats[stat];
            }
        }

        #endregion

        #region props

        public int this[StatType index]
        {
            get { return this[(int)index - 1]; }
            set { this[(int)index - 1] = value; }
        }
        public int this[int index]
        {
            get
            {
                if (index >= 0 && index < stats.Length)
                {
                    return stats[(int)index];
                }
                return 0;
            }
            set
            {
                if (index >= 0 && index < stats.Length)
                {
                    stats[(int)index] = value;
                }
            }
        }
        public int AtkLv { get { return this[StatType.Atk]; } }
        public int DefLv { get { return this[StatType.Def]; } }
        public int SpeedLv { get { return this[StatType.Speed]; } }
        public int SpAtkLv { get { return this[StatType.SpAtk]; } }
        public int SpDefLv { get { return this[StatType.SpDef]; } }
        public int AccuracyLv { get { return this[StatType.Accuracy]; } }
        public int EvasionLv { get { return this[StatType.Evasion]; } }

        #endregion

        #region ICloneable

        public object Clone()
        {
            return new BattleStats(this);
        }

        #endregion

        #region IEnumerator

        public IEnumerator<int> GetEnumerator()
        {
            foreach (int value in stats)
            {
                yield return value;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.stats.GetEnumerator();
        }

        public IEnumerable<int> Get5D()
        {
            foreach (var stat in Type5D)
            {
                yield return this[stat];
            }
        }

        #endregion

    }
}